#
# @lc app=leetcode.cn id=77 lang=python
#
# [77] 组合
#

# @lc code=start
class Solution(object):
    def combine(self, n, k):
        """
        :type n: int
        :type k: int
        :rtype: List[List[int]]
        """
        self.n = n
        self.k = k
        self.result = []
        self.result_item = []
        self.loop(1)
        return self.result


    def loop(self, start):
        if len(self.result_item) == self.k:
            self.result.append(self.result_item[:])
            return

        for i in range(start, self.n-self.k+2+len(self.result_item)):
            self.result_item.append(i)
            self.loop(i+1)
            self.result_item.pop()
        
# @lc code=end

